import { takeEvery, takeLatest, put } from 'redux-saga/effects'
import { message } from 'antd'
import { fetchUserInfo, fetchDic } from '@effects/global'
import * as homeSaga from '@effects/home'

export default function* appSaga() {
  console.log('hello saga')
  // 监听请求成功
  yield takeEvery('REQUEST_SUCCESS', function ({ msg }: successActionType) {
    message.success(msg)
  })
  // 监听请求异常
  yield takeLatest('REQUEST_FAILED', function* ({ error }: errorActionType) {
    error && error.message && message.error(error.message)
    yield put({ type: 'G/OFF_pLoading' })
    yield put({ type: 'G/OFF_loading' })
    yield put({ type: 'G/OFF_searching' })
    yield put({ type: 'G/OFF_uploading' })
  })

  yield takeEvery('G/fetchUserInfo', fetchUserInfo)
  yield takeEvery('G/fetchDic', fetchDic)

  yield takeEvery('HOME/fetchTable0', homeSaga.fetchTable0)
  yield takeEvery('HOME/fetchTable1', homeSaga.fetchTable1)
}
